<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>


<?php $_order = $this->getOrder() ?>
<?php

$baseurl = Mage::getBaseUrl();
$skinPath = $this->getSkinUrl();

$baseurl = $this->getBaseUrl();
$realOrderId = $_order->getRealOrderId();
$resource = Mage::getSingleton('core/resource');
$couponemail = $resource->getConnection('core_write');
$tprefix = (string)Mage::getConfig()->getTablePrefix();
$uniquenumber = '';
$giftCouponCheck = $couponemail->fetchRow("select * from ".$tprefix."ordercustomer where order_id ='".$_order->getId()."'");

if(isset($giftCouponCheck['uniqueid'])) {
    $uniquenumber = $giftCouponCheck['uniqueid'];
    $customerName = $giftCouponCheck['customer_name'];


}
$store = Mage::app()->getStore();
$order = Mage::getModel('sales/order')->load($_order->getId());
$items = $order->getAllItems();
$itemcount=count($items);
$Productname='';
$unitPrice='';
$qty=''; 
foreach ($items as $itemId => $item) {
    $Productname = $item->getName();
    $unitPrice=$item->getPrice();
    $specialPrice=$item->getSpecialPrice();
    $qty=$item->getQtyToInvoice();
    $model = Mage::getModel('catalog/product');
    $productId = $item->getProductId();
    $url = "productid".$productId;
    //  $barcodeemail = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).$url.'/lable'.$uniquenumber.'.png';
    $productdetail = $model->load($item->getProductId());
    $currentproductimage = Mage::helper('catalog/image')->init($productdetail, 'image')->resize(386,338);
    $specialPrice=$productdetail->getSpecialPrice();
    $Productname = $productdetail->getName();
    $unitPrice=$productdetail->getPrice();
    $discount_price =  $unitPrice-$specialPrice;
    $discount = ($discount_price*100)/ $unitPrice;
    $discount = round($discount);
    $currentdiscount = $discount;
    $couponValid =  $productdetail->getEnjoyby();
    $couponCondition =  $productdetail->getLimits();
    $phone =  $productdetail->getQuestions();
    $Companywebsite =  $productdetail->getCustomer_website();
    $Companyname=$productdetail->getCompanyName();
    $Companyaddress=$productdetail->getCustomersite();
    $product_worth = $productdetail->getPrice();
    $product_description = $productdetail->getDescription();
}
?>
<div style="margin:  auto;width: 590px;" align="center">
    <table cellpadding="0" cellspacing="0" align="center"  width="590">
        <tr>
            <td align="center">

                <table   style="border:5px solid #dbdbdb;" bgcolor="white"  border="5"  cellpadding="0" cellspacing="0" rules="groups" width="590"     >
                    <tr>
                        <td width="20"></td>
                        <td valign="top" width="470">
                            <p><a href="<?php echo Mage::app()->getStore()->getHomeUrl(); ?>" style="color:#1E7EC8;"><img src="<?php echo  $this->getSkinUrl('images/logo_email.png'); ?>" alt="<?php echo $store->getName(); ?>" border="0"/></a></p></td>
                        <td width="120"><img src="<?php echo $this->getSkinUrl('images/sale.jpg'); ?>"  width="107" height="67"/></td>
                    </tr>
                    <tr>
                        <td colspan="3" height="10"></td>
                    </tr>
                </table>
                <table   bordercolor=""   cellpadding="0"  bgcolor="white" cellspacing="0" rules="cols" width="580"  style="border-left:5px solid #DBDBDB;border-right:5px solid #DBDBDB;"    >
                    <tr>
                        <td>
                            <table cellpadding="0" cellspacing="0">
                                <tr>
                                    <td height="20" colspan="3"></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table cellpadding="0" cellspacing="0" width="580">
                                <tr>

                                    <td width="20"></td>
                                    <td width="586"><font face="Georgia" size="4"  color="#333" ><?php echo $Productname; ?></font></td>

                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table cellpadding="0" cellspacing="0">
                                <tr>
                                    <td colspan="3" height="20"></td>

                                </tr>
                            </table>
                        </td>

                    </tr>
                    <tr>
                        <td>
                            <table cellpadding="0" cellspacing="0">
                                <tr>
                                    <td valign="top" width="170">
                                        <table cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td background="<?php echo $this->getSkinUrl('images/worthimg.jpg'); ?>"  width="170" height="130" style="background-repeat:no-repeat;">    <table cellpadding="0" cellspacing="0">
                                                        <tr>
                                                            <td height="65"></td>
                                                        </tr>
                                                        <tr>
                                                            <td align="center" width="170"><font face="Georgia" size="6" color="#333" ><strong> $ <?php echo floor($specialPrice); ?></strong></font></td>
                                                        </tr>

                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td height="10"></td>

                                            </tr>




                                            <tr>

                                                <td align="center">
                                                    <table cellpadding="0" cellspacing="0">
                                                        <tr>
                                                            <td width="10"></td>
                                                            <td><font color="#0066CC"><a href="<?php echo $Companywebsite; ?>"><?php echo $Companywebsite; ?></a></font></td>
                                                        </tr>

                                                    </table> </td>

                                            </tr>
                                        </table>
                                    </td>
                                    <td width="390"  valign="top"><img src="<?php echo $currentproductimage; ?>" width="400" height="306"/></td>
                                </tr>
                                <tr>
                                    <td colspan="2" height="15"></td>

                                </tr>

                                <tr>
                                    <td colspan="2">
                                        <table cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td width="10"></td>
                                                <td><font face="Arial" size="2" color="#666"><?php echo $product_description; ?></font></td>
                                            </tr>

                                        </table> </td>
                                </tr>
                                <tr>
                                    <td colspan="2" height="15"></td>

                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td ><img src="<?php echo $this->getSkinUrl('images/borderimg.jpg'); ?>"  width="580" height="4"/></td></tr>
                    <tr>

                        <td></td>

                    </tr>

                    <tr>
                        <td height="5"></td>

                    </tr>
                    <tr>
                        <td valign="top">
                            <table cellpadding="0" cellspacing="0">

                                <tr>

                                    <td width="30"></td>
                                    <td valign="top">
                                        <table cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td width="95"><font face="Arial" size="2" color="#666">Name</font></td>
                                                <td width="10">:</td>
                                                <td><font face="Georgia" size="2" color="#333"><strong><?php echo $customerName; ?></strong></font></td>
                                            </tr>
                                            <tr>
                                                <td width="95"><font face="Arial" size="2" color="#666">Coupon ID</font></td>
                                                <td width="10">:</td>
                                                <td><font face="Georgia" size="2" color="#333"><strong><?php echo $uniquenumber; ?></strong></font></td>
                                            </tr>
                                            <tr>
                                                <td width="95"><font face="Arial" size="2" color="#666">Valid Upto</font></td>
                                                <td width="10">:</td>
                                                <td><font face="Georgia" size="2" color="#333"><strong><?php echo $couponValid;  ?></strong></font></td>
                                            </tr>
                                            <tr>
                                                <td width="95"><font face="Arial" size="2" color="#666">Redeem at</font></td>
                                                <td width="10">:</td>
                                                <td><font face="Georgia" size="2" color="#333"><strong><?php echo $Companyaddress; ?></strong></font></td>
                                            </tr>
                                        </table>
                                    </td>
                                    <td width="30"></td>
                                    <td>
                                        <table cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td><font color="#333" size="3" face="Arial">YOU SAVE&nbsp; </font></td>
                                                <td><font color="#999" size="6" face="Arial"><strong><?php echo $discount; ?></strong></font></td>
                                                <td><font color="#333" size="6" face="Arial"><strong>&nbsp;%</strong></font></td>
                                            </tr>
                                        </table>
                                    </td>

                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <table cellpadding="0" cellspacing="0">
                    <tr>
                        <td background="<?php echo  $this->getSkinUrl('images/emailbottombg.jpg'); ?>"  width="590" height="48" >
                            <table cellpadding="0" cellspacing="0" width="590">
                                <tr>
                                    <td height="20"></td>

                                </tr>
                                <tr>
                                    <td width="80" ></td>
                                    <td>
                                        <a href="mailto:{{config path='trans_email/ident_support/email'}}"><font face="Arial" color="#0099CC" size="1"><?php //echo $Companyaddress; ?></font></a><font face="Arial" color="#666" size="1">  Call us:<?php echo $phone;?></font>
                                    </td>
                                </tr></table>

                        </td>
                    </tr>
                </table>

            </td>
        </tr>

    </table></div>
<script type="text/javascript">decorateTable('my-orders-table', {'tbody' : ['odd', 'even'], 'tbody tr' : ['first', 'last']})</script>
<script type="text/javascript">window.print();</script>
